package fr.inserm.u915.organifooyi.lang;

public abstract class UnsignedNumber<T extends Number>
	{
	private T value;

	public static class UDouble extends UnsignedNumber<Double>
		{
		public UDouble(Double value)
			{
			super(value);
			}
		public UDouble(String value)
			{
			this(Double.parseDouble(value));
			}
		}

	public static class ULong extends UnsignedNumber<Long>
		{
		public ULong(Long value)
			{
			super(value);
			}
		public ULong(String value)
			{
			this(Long.parseLong(value));
			}
		}

	
	public static class UInteger extends UnsignedNumber<Integer>
		{
		public UInteger(Integer value)
			{
			super(value);
			}
		public UInteger(String value)
			{
			this(Integer.parseInt(value));
			}
		}

	public static class UShort extends UnsignedNumber<Short>
		{
		public UShort(Short value)
			{
			super(value);
			}
		public UShort(String value)
			{
			this(Short.parseShort(value));
			}
		}

	
	protected  UnsignedNumber(T value)
		{
		if(value==null) throw new NullPointerException("value=null");
		this.value=value;
		if(this.value.doubleValue()<0.0) throw new NumberFormatException("not an unsigned number:"+value);
		}
	public double doubleValue()
		{
		return this.value.doubleValue();
		}
	@Override
	public int hashCode() {
		return this.value.hashCode();
		}
	
	@SuppressWarnings("unchecked")
	@Override
	public boolean equals(Object obj)
		{
		if(obj==this) return true;
		if(obj==null || obj.getClass()!=this.getClass()) return false;
		return value.equals(((UnsignedNumber<T>)obj).value);
		}
	
	@Override
	public String toString() {
		return value.toString();
		}
	}
